package springMVC.getParams.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author quan
 * @Description 后端参数重命名：(@RequestParam(value = "n",required = false)  String name)
 * @Date 2023/7/21 16:20
 */

@Controller
@RequestMapping("/web")
public class Demo4_BackRename {
    @ResponseBody
    @RequestMapping("/get4")

    //如果url不传递n值，会直接报错，报错显示n显示是一个必传参数,这时候就要设置required = false
    public String get4(@RequestParam(value = "n",required = false)  String name){
        return "修改后的名称为="+name;
    }

    //前端传递n，后端修改为name
//    public String get4(@RequestParam("n") String name){
//        return "修改后的名称为="+name;
//    }
}
